package za.ac.wits.elen7045.scraper.interfaces;

import java.util.HashMap;

import za.ac.wits.elen7045.enums.DataKey;
import za.ac.wits.elen7045.scraper.models.ScraperSession;

public abstract class BaseScraperMappingEntities {

	protected HashMap<DataKey, Integer> numberEntities;
	protected HashMap<DataKey, String> stringEntities;
	
	public BaseScraperMappingEntities() {
		numberEntities = new HashMap<DataKey, Integer>();
		stringEntities = new HashMap<DataKey, String>();
	}
	
	protected void addEntity(DataKey key, Integer value) {
		if (!stringEntities.containsKey(key)) {
			stringEntities.put(key,  value.toString());
			return;
		}
		Integer currentValue = Integer.parseInt(stringEntities.get(key));
		currentValue += value;
		stringEntities.put(key, currentValue.toString());
	}
	
	protected void addEntity(DataKey key, String value) throws Exception {
		if (stringEntities.containsKey(key))
			throw new Exception("Key already exists");
		stringEntities.put(key,  value);
	}
	
	public abstract HashMap<DataKey, String> getMappedEntities(ScraperSession session) throws Exception;
}
